package com.oncliedisk.administrator.ui;

import android.view.View;
import android.widget.Toast;

import com.oncliedisk.administrator.onlinedisk.R;
import com.oncliedisk.administrator.utils.ReadDataFromContentProvider;

/**
 * Created by Administrator on 2015/12/14 0014.
 */
public class UploadDocumentActiv extends BaseUploadActivity {
    @Override
    public void fillData() {
        //加载数据，进度条可见
        ll_loading.setVisibility(View.VISIBLE);
        new Thread(new Runnable() {
            @Override
            public void run() {
                data = ReadDataFromContentProvider.getDocumentlist(UploadDocumentActiv.this) ;
                if(null == data || data.size() == 0) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //没有数据加载，进度条不可见
                            ll_loading.setVisibility(View.INVISIBLE);
                            Toast.makeText(UploadDocumentActiv.this, "没有扫描到文档", Toast.LENGTH_LONG).show() ;
                        }
                    });
                    return ;
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        //数据加载完毕，进度条不可见
                        ll_loading.setVisibility(View.INVISIBLE);
                        if(adapter == null) {
                            adapter = new MyAdapter(UploadDocumentActiv.this, data);
                            listview.setAdapter(adapter) ;
                        }else {
                            adapter.notifyDataSetChanged();
                        }
                    }
                });
            }
        }).start();
    }


    @Override
    protected void setIcon(ViewHolder holder, int position) {

        /**
         *  add("text/plain");
         add("text/plain");
         add("application/pdf");
         add("application/msword");
         add("application/vnd.ms-excel");
         add("application/vnd.ms-excel");
         */
        switch (data.get(position).getMimeType() ) {
            case "text/plain":
                holder.iv_icon.setImageResource(R.drawable.icon_list_txtfile);
                break;
            case "application/pdf":
                holder.iv_icon.setImageResource(R.drawable.icon_list_pdf);
                break;
            case "application/msword":
                holder.iv_icon.setImageResource(R.drawable.icon_list_doc);
                break;
            case "application/vnd.ms-excel":
                holder.iv_icon.setImageResource(R.drawable.icon_list_excel);
                break;
            case "application/vnd.ms-powerpoint":
                holder.iv_icon.setImageResource(R.drawable.icon_list_ppt);
                break;
        }

    }

    @Override
    protected void setUploadTitle() {
        tv_title.setText("请选择文档频上传");
    }

}
